<template>
  <div class="push"
  >
    <div class="push_avatar">
      <div
          class="push_face"
          :style="{ backgroundImage: `url(${push.user.faceUrl})` }"
      />
      <p class="push_text">
        <span class="name">{{ push.user.name }}</span>
        <span class="push_date">{{ push.date }}</span>
      </p>
      <div class="push_add">
      </div>
    </div>

    <p class="push_content">{{ push.content }}</p>
    <div class="push_action">
      <span>
        <i :class="!(isLike||isLike2)?'iconfont icon-dianzan o':'iconfont icon-kaixin oo'" @click="saylike"></i>
      </span>
    </div>
  </div>
</template>

<script>
import {Toast} from 'vant';
import {mapMutations} from "vuex";

export default {
  props: {
    push: {
      type: Object,
      required: true
    },
    isLike: {
      type: Boolean,
      required: false,
      default: false
    }
  },
  data() {
    return {
      isLike2: false
    }
  },
  filters: {
    dateString(val) {
      return val.toDateString()
    }
  },
  methods: {
    ...mapMutations(['toLike']),
    saylike() {
      if (!(this.isLike||this.isLike2)) {
        this.isLike2 = true
        this.toLike(this.push.id)
        Toast({
          message: '赞👍',
          duration:200
        });
      }else {
        Toast({
          message: '赞过了🥺',
          duration:500
        });
      }
    }
  }
}
</script>

<style lang="less">
.push {
  position: relative;
  margin: 10px 20px 10px 20px;
  padding: 20px;
  padding-bottom: 0;
  border-radius: 16px;
  background-color: white;
  transform-origin: top;

}

.push_avatar {
  position: relative;
  display: flex;
  align-items: center;
  margin-right: -16px;
}

.push_face {
  display: block;
  width: 50px;
  height: 50px;
  border-radius: 100%;
  background-size: cover;
}

.push_text {
  display: flex;
  flex: 1;
  flex-direction: column;
  margin-left: 20px;
  line-height: 20px;

  .name {
    font-weight: 600;
    font-size: 14px;
    text-align: left;
    color: #222;
  }

  .push_date{
    font-style: italic;
    font-size: 12px;
    color: #999;
  }
}

.iconfont.icon-Heart {
  padding: 20px;
  color: #aaa;
}

.push_content {
  margin-top: 20px;
  color: #999;
  font-size: 14px;
  line-height: 1.5em;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.push_action {
  display: flex;
  justify-content: flex-end;
  margin: 0 -16px;

  span {
    padding: 8px 16px 8px 8px;
  }
}

.iconfont.icon-Chat {
  color: #222;
  font-size: 24px;
}

.iconfont.icon-kaixin {
  color: #222;
}

.o {
  font-size: 24px;
  transition: all 1s;
}

.oo {
  font-size: 16px;
  transition: all 1s;
}


</style>
